<template>
    <div class="invite-box" v-loading="loading">
        <div style="font-size:14px;font-weight:600;margin:10px 0;">邀请人</div>
        <el-table
            :data="inviteFrom"
            border
            style="width: 100%">
            <el-table-column
                fixed
                prop="date"
                label="编号">
                <template>
                    <span>1</span>
                </template>
            </el-table-column>
            <el-table-column
                label="头像">
                <template slot-scope="scope">
                    <div class="user-icon">
                        <img :src="scope.row.userHead" alt="">
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                width="150"
                label="用户昵称">
                <template slot-scope="scope">
                    <div>
                        <span class="table-btn" @click="goUserDetail(scope.row.userId)">{{scope.row.userName || '-'}}</span>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="userId"
                label="用户ID">
            </el-table-column>
            <el-table-column
                width="120"
                prop="phone"
                label="手机号">
                <template slot-scope="scope">
                    <div>{{scope.row.phone || '-'}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="wechatNum"
                width="150"
                label="微信号">
                <template slot-scope="scope">
                    <div>{{scope.row.wechatNum || '-'}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="qqNum"
                width="150"
                label="QQ号">
                <template slot-scope="scope">
                    <div>{{scope.row.qqNum || '-'}}</div>
                </template>
            </el-table-column>
            <el-table-column
                width="108"
                prop="registerTime"
                label="注册时间">
                <template slot-scope="scope">
                     <div style="text-align:center;">{{initTime(scope.row.registerTime)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                width="108"
                prop="recentLoginTime"
                label="最近登录">
                <template slot-scope="scope">
                     <div style="text-align:center;">{{initTime(scope.row.recentLoginTime)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="superReward"
                label="上级提成">
                <template slot-scope="scope">
                    <div v-if="scope.row.superReward">{{scope.row.superReward || '-'}}元</div>
                    <div v-else>-</div>
                </template>
            </el-table-column>
            <el-table-column
                min-width="100"
                prop="superPreReward"
                label="上上级提成">
                <template slot-scope="scope">
                    <div v-if="scope.row.superPreReward">{{scope.row.superPreReward || '-'}}元</div>
                    <div v-else>-</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="inviteReward"
                min-width="150"
                label="直邀奖励">
                <template slot-scope="scope">
                    <div v-if="scope.row.inviteReward">{{scope.row.inviteReward || '0'}}元 (未到钱包)</div>
                    <div v-else>-</div>
                    <div v-if="scope.row.inviteRewardGet">{{scope.row.inviteRewardGet || '0'}}元 <span style="color:#67C23A;">(已到钱包)</span></div>
                </template>
            </el-table-column>
            <el-table-column
                prop="spreadInviteReward"
                min-width="150"
                label="扩散奖励">
                <template slot-scope="scope">
                    <div v-if="scope.row.spreadInviteReward">{{scope.row.spreadInviteReward || '0'}}元 (未到钱包)</div>
                    <div v-else>-</div>
                    <div v-if="scope.row.spreadInviteRewardGet">{{scope.row.spreadInviteRewardGet || '0'}}元 <span style="color:#67C23A;">(已到钱包)</span></div>
                </template>
            </el-table-column>
            <el-table-column
                prop="rewardTotal"
                label="累计奖励">
                <template slot-scope="scope">
                    <div v-if="scope.row.rewardTotal">{{scope.row.rewardTotal || '0'}}元</div>
                    <div v-else>-</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="evilStatus"
                fixed="right"
                label="恶意等级">
                <template slot-scope="scope">
                    <div>{{scope.row.evilStatus || '-'}}</div>
                </template>
            </el-table-column>
        </el-table>

        <div style="font-size:14px;font-weight:600;margin:10px 0;">我的邀请</div>
        <el-table
            :data="inviteList"
            border
            style="width: 100%">
            <el-table-column
                fixed
                prop="date"
                label="编号">
                <template slot-scope="scope">
                    <span>{{scope.row.number}}</span>
                </template>
            </el-table-column>
            <el-table-column
                label="头像">
                <template slot-scope="scope">
                    <div class="user-icon">
                        <img :src="scope.row.userHead" alt="">
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                width="150"
                label="用户昵称">
                <template slot-scope="scope">
                    <div>
                        <span class="table-btn" @click="goUserDetail(scope.row.userId)">{{scope.row.userName || '-'}}</span>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="userId"
                label="用户ID">
            </el-table-column>
            <el-table-column
                width="120"
                prop="phone"
                label="手机号">
                <template slot-scope="scope">
                    <div>{{scope.row.phone || '-'}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="wechatNum"
                width="150"
                label="微信号">
                <template slot-scope="scope">
                    <div>{{scope.row.wechatNum || '-'}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="qqNum"
                width="150"
                label="QQ号">
                <template slot-scope="scope">
                    <div>{{scope.row.qqNum || '-'}}</div>
                </template>
            </el-table-column>
            <el-table-column
                width="108"
                prop="registerTime"
                label="注册时间">
                <template slot-scope="scope">
                     <div style="text-align:center;">{{initTime(scope.row.registerTime)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                width="108"
                prop="recentLoginTime"
                label="最近登录">
                <template slot-scope="scope">
                     <div style="text-align:center;">{{initTime(scope.row.recentLoginTime)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="superReward"
                label="上级提成">
                <template slot-scope="scope">
                    <div v-if="scope.row.superReward">{{scope.row.superReward}}元</div>
                    <div v-else>-</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="superPreReward"
                min-width="100"
                label="上上级提成">
                <template slot-scope="scope">
                    <div v-if="scope.row.superPreReward">{{scope.row.superPreReward}}元</div>
                    <div v-else>-</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="inviteReward"
                min-width="150"
                label="直邀奖励">
                <template slot-scope="scope">
                    <div v-if="scope.row.inviteReward">{{scope.row.inviteReward || '0'}}元 (未到钱包)</div>
                    <div v-else>-</div>
                    <div v-if="scope.row.inviteRewardGet">{{scope.row.inviteRewardGet || '0'}}元 <span style="color:#67C23A;">(已到钱包)</span></div>
                </template>
            </el-table-column>
            <el-table-column
                min-width="150"
                prop="spreadInviteReward"
                label="扩散奖励">
                <template slot-scope="scope">
                    <div v-if="scope.row.spreadInviteReward">{{scope.row.spreadInviteReward || '0'}}元 (未到钱包)</div>
                    <div v-else>-</div>
                    <div v-if="scope.row.spreadInviteRewardGet">{{scope.row.spreadInviteRewardGet || '0'}}元 <span style="color:#67C23A;">(已到钱包)</span></div>
                </template>
            </el-table-column>
            <el-table-column
                prop="rewardTotal"
                label="累计奖励">
                <template slot-scope="scope">
                    <div v-if="scope.row.rewardTotal">{{scope.row.rewardTotal || '0'}}元</div>
                    <div v-else>-</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="evilStatus"
                fixed="right"
                label="恶意等级">
                <template slot-scope="scope">
                    <div>{{scope.row.evilStatus || '-'}}</div>
                </template>
            </el-table-column>
        </el-table>

        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'
export default {
    data () {
        return {
            inviteList: [], // 我的邀请
            inviteFrom: [], // 邀请人
            loading: false,
            status: 0,
            pageNum: 1,
            pageSize: this._pageSize,
            total: 0
        }
    },

    props: ['detail'],

    created () {
        if (this.detail && this.detail.userId) {
            this.getDetail()
        }
    },

    methods: {
        async getDetail () {
            if (this.loading) return
            this.loading = true
            let res = await this.$http.get('/user/getUserInviteRecord', {
                params: {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    userId: this.detail.userId
                }
            })
            if (res.code === '0') {
                if (res.data.userInviteInfoVo && res.data.userInviteInfoVo.userId) {
                    this.inviteFrom = [res.data.userInviteInfoVo]
                } else {
                    this.inviteFrom = []
                }
                this.inviteList = res.data.myInvitePersionInfoVoList
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
            this.loading = false
        },

        // 初始化时间
        initTime (time) {
            if (time) {
                return formatDate(new Date(time), 'YYYY-MM-DD HH:MM')
            } else {
                return '-'
            }
        },

        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getDetail()
        },

        pageChange (val) {
            this.pageNum = val
            this.getDetail()
        },

        // 查看用户详情
        goUserDetail (id) {
            const { href } = this.$router.resolve({
                path: '/dataReport/userInfo',
                query: {
                    id
                }
            })
            window.open(href, '_blank')
        }
    }
}
</script>

<style lang="scss" scoped>
    .invite-box {
        .select-box {
            margin-bottom: 10px;
        }
        .table-btn {
            color: #409EFF;
            cursor: pointer;
            &:hover {
                text-decoration: underline;
            }
        }
        .user-icon {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            margin: 0 auto;
            overflow: hidden;
            > img {
                width: 100%;
                height: 100%;
            }
        }

        .tools {
            margin-top: 10px;
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
</style>
